//
//  SRLoginView.m
//  SportRing
//
//  Created by Apple on 14/10/23.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRLoginView.h"

@interface SRLoginView ()

@property (nonatomic, weak) UITextField * mobileTF;
@property (nonatomic, weak) UITextField * passwordTF;
@property (nonatomic, weak) IBOutlet LGButton * loginBtn;
@property (nonatomic, weak) IBOutlet LGButton * gotoRegisterBtn;

@end

@implementation SRLoginView

-(void)awakeFromNib
{
    [super awakeFromNib];
    
    [self setupButtons];
    
    if ([Utils userIsLogin]) {
        
        [self setUserLoginInfo:[SRMe findUserAndCreateIfNotExistByName:[Utils loginedUserName]]];
        
    }
    
    RAC(self.loginBtn, enabled) = [RACSignal combineLatest:@[self.mobileTF.rac_textSignal,
                                                             self.passwordTF.rac_textSignal]
                                                    reduce:^(NSString * mobile, NSString * password) {
                                                        return @(mobile.length > 0 && password.length > 0);
                                                    }];
    
    @weakify(self);
    [[self.loginBtn rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(id x) {
         [self_weak_.delegate doLoginAction:self_weak_.mobileTF.text
                                   password:self_weak_.passwordTF.text];
     }];
    NSLog(@"%f",[UIScreen mainScreen].bounds.size.height);
    if (!([UIScreen mainScreen].bounds.size.height > 480)) {
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"loginBg480"]];
    }else
    {
        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"loginBg"]];
    }
    
}

- (void)setUserLoginInfo:(SRMe *)me
{
    self.mobileTF.text = me.userName;
    self.passwordTF.text = me.userPwd;
}

- (void)setupButtons
{
//    LGButtonColorPair * disableColor1 = [LGButtonColorPair colorPairWithTitleColor:[UIColor whiteColor]
//                                                                   backgroundColor:[UIColor clearColor]];
//    LGButtonColorPair * normalColor1 = [LGButtonColorPair colorPairWithTitleColor:[UIColor whiteColor]
//                                                                 backgroundColor:[UIColor clearColor]];
//    [self.loginBtn setColorPairs:@{@(LG_BUTTON_STATE_TYPE_NORMAL):normalColor1,
//                                   @(LG_BUTTON_STATE_TYPE_DISABLED):disableColor1}];
    
    
//    LGButtonColorPair * normalColor2 = [LGButtonColorPair colorPairWithTitleColor:[UIColor whiteColor]
//                                                                  backgroundColor:[UIColor clearColor]];
//    [self.gotoRegisterBtn setColorPairs:@{@(LG_BUTTON_STATE_TYPE_NORMAL):normalColor2}];
}

@end
